package com.byapp.fast.common.converter;


import com.byapp.fast.modules.contract.dto.BetOddsDTO;
import com.byapp.fast.modules.match.entity.MatchOddsEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class BetOddsDTOConverter {

    public static List<BetOddsDTO> mapToTarget(MatchOddsEntity matchOddsEntity) {
        // 获取胜平负赔率
        String win = matchOddsEntity.getWin();
        String even = matchOddsEntity.getEven();
        String lost = matchOddsEntity.getLost();

        Map<Integer, String> map = new HashMap<>();

        map.put(0, lost);
        map.put(1, even);
        map.put(3, win);

        // 对象转换
        return map.entrySet().stream()
                .filter(entry -> StringUtils.isNotEmpty(entry.getValue()))
                .map(entry ->
                        new BetOddsDTO()
                                .setBetOdds(entry.getKey())
                                .setItemCode(entry.getValue())
                ).collect(Collectors.toList());
    }
}
